#罗马数字转整数
class Solution:
    def romanToInt(self, s: str) -> int:
        roman_dict = {
            'I': 1,
            'V': 5,
            'X': 10,
            'L': 50,
            'C': 100,
            'D': 500,
            'M': 1000
        }
        total = 0
        for i in range(len(s) - 1):
            current = roman_dict[s[i]]
            next_val = roman_dict[s[i+1]]
            if current < next_val:
                total -= current
            else:
                total += current
        total += roman_dict[s[-1]]
        return total